package com.flnet.web.controller.foxwash;

import com.flnet.common.annotation.Log;
import com.flnet.common.base.AjaxResult;
import com.flnet.common.enums.BusinessType;
import com.flnet.common.page.TableDataInfo;
import com.flnet.common.utils.poi.ExcelUtil;
import com.flnet.foxwash.domain.WOrder;
import com.flnet.foxwash.service.IWOrderService;
import com.flnet.framework.web.base.BaseController;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 订单 信息操作处理
 * 
 * @author flnet
 * @date 2019-03-20
 */
@Controller
@RequestMapping("/foxwash/wOrder")
public class WOrderController extends BaseController
{
    private String prefix = "foxwash/wOrder";
	
	@Autowired
	private IWOrderService wOrderService;
	
	@RequiresPermissions("foxwash:wOrder:view")
	@GetMapping()
	public String wOrder()
	{
	    return prefix + "/wOrder";
	}
	
	/**
	 * 查询订单列表
	 */
	@RequiresPermissions("foxwash:wOrder:list")
	@PostMapping("/list")
	@ResponseBody
	public TableDataInfo list(WOrder wOrder)
	{
		startPage();
        List<WOrder> list = wOrderService.selectWOrderList(wOrder);
		return getDataTable(list);
	}
	
	
	/**
	 * 导出订单列表
	 */
	@RequiresPermissions("foxwash:wOrder:export")
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(WOrder wOrder)
    {
    	List<WOrder> list = wOrderService.selectWOrderList(wOrder);
        ExcelUtil<WOrder> util = new ExcelUtil<WOrder>(WOrder.class);
        return util.exportExcel(list, "wOrder");
    }
	
	/**
	 * 新增订单
	 */
	@GetMapping("/add")
	public String add()
	{
	    return prefix + "/add";
	}
	
	/**
	 * 新增保存订单
	 */
	@RequiresPermissions("foxwash:wOrder:add")
	@Log(title = "订单", businessType = BusinessType.INSERT)
	@PostMapping("/add")
	@ResponseBody
	public AjaxResult addSave(WOrder wOrder)
	{		
		return toAjax(wOrderService.insertWOrder(wOrder));
	}

	/**
	 * 修改订单
	 */
	@GetMapping("/edit/{orderId}")
	public String edit(@PathVariable("orderId") Long orderId, ModelMap mmap)
	{
		WOrder wOrder = wOrderService.selectWOrderById(orderId);
		mmap.put("wOrder", wOrder);
	    return prefix + "/edit";
	}
	
	/**
	 * 修改保存订单
	 */
	@RequiresPermissions("foxwash:wOrder:edit")
	@Log(title = "订单", businessType = BusinessType.UPDATE)
	@PostMapping("/edit")
	@ResponseBody
	public AjaxResult editSave(WOrder wOrder)
	{		
		return toAjax(wOrderService.updateWOrder(wOrder));
	}
	
	/**
	 * 删除订单
	 */
	@RequiresPermissions("foxwash:wOrder:remove")
	@Log(title = "订单", businessType = BusinessType.DELETE)
	@PostMapping( "/remove")
	@ResponseBody
	public AjaxResult remove(String ids)
	{		
		return toAjax(wOrderService.deleteWOrderByIds(ids));
	}
	
}
